#include "mainwindow.h"
//#include "popmenu.h"
#include <QPushButton>
#include <QWidget>
#include <QString>
#include <QIcon>
#include <QMenu>
#include <QDebug>
#include <QLabel>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    setStyleSheet("background-color:white;");
    setAutoFillBackground( true );
    createButton();
    setWindowIcon(QIcon("://picture/kurisu.jpeg"));
}

MainWindow::~MainWindow()
{

}

void MainWindow::createButton(){
    //实例化一个按钮
    QPushButton *button = new QPushButton(this);
    button->move(10,10);
    QString style = "QPushButton{background-color:pink;"
            "color:white}";
//    QString style = "QPushButton::hover{background-color:red;}";
    //这里不能出现样式设置，以后探索一下是为什么
    button->setStyleSheet(style);
    button->setEnabled(true);
    button->setText("Press Me ~");
//    PopMenu *menu = new PopMenu(button, this);
//    button->setMenu(menu);
    //设置点击button之后显示下拉列表
    QMenu *menu = new QMenu(this);
    menu->setStyleSheet("background-color:pink");
    menu->addAction(new QAction("Item 1", this));
    menu->addAction(new QAction("Item 2", this));
    connect(menu, &QMenu::triggered, this, &MainWindow::testSlotLabel);

    button->setMenu(menu);

}

void MainWindow::testSlotLabel(QAction *action)
{
    qDebug() << "Show Show" << action->text();

    QString text = "Show Show" + action->text();

    //实例化一个显示文字的label
    QLabel *label = new QLabel(this);
    label->setText(text);


}

void MainWindow::changeBackGround()
{
    //改变背景的颜色或者样式
    QWidget *myWidget = new QWidget(this);
    //myWidget->setGeometry(0,0,300,300);
    QPalette pal = palette();
    pal.setColor(QPalette::Background, Qt::white);
    myWidget->setAutoFillBackground(true);
    myWidget->setPalette(pal);
    myWidget->show();
}

void MainWindow::changeWindow()
{
    //改变窗口的相关属性
    setWindowIcon(QIcon(":/../图片/kurisu.jpeg"));
}

